﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DatabaseManagement.DataObjects.Interfaces;

namespace DatabaseManagement.DataObjects
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public class Database : IDataObject
    {
        [System.Xml.Serialization.XmlElementAttribute("Tables", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public List<Table> ColTables { get; set; }
        
        [System.Xml.Serialization.XmlElementAttribute("StoredProcedures", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public List<StoredProcedure> ColProcedures { get; set; }

        [System.Xml.Serialization.XmlElementAttribute("Functions", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public List<Function> ColFunction { get; set; }

        [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string Name { get; set; }

        public Database()
        {
            ColFunction = new List<Function>();
            ColTables = new List<Table>();
            ColProcedures = new List<StoredProcedure>();
        }

        public bool CheckExistingTable(string tableName, Table currentTable = null)
        {
            foreach (var table in ColTables)
            {
                if (table.Name.Trim().ToUpper() == tableName.Trim().ToUpper() && (currentTable == null || currentTable != table))
                {
                    return true;
                }
            }
            return false;
        }
    }
}
